package com.tool4j.controller;

import com.tool4j.entity.Feedback;
import com.tool4j.service.FeedbackService;
import com.tool4j.util.http.IPUtil;
import com.tool4j.util.http.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/feedback")
public class FeedbackController {

    @Autowired
    private FeedbackService feedbackService;

    @Autowired
    private IPUtil ipUtil;

    @PostMapping("/submit")
    public Result<Void> submit(ServerHttpRequest request, @RequestBody Feedback params) {
        String ip = ipUtil.getIp(request);
        params.setIp(ip);
        params.setRegion(ipUtil.searchRegion(ip));
        feedbackService.saveData(params);
        return Result.ok();
    }

}
